TableServiceExtensionMethods.AsTableServiceQuery Method

Storage Client Library NET API

[This topic is part of the Microsoft Azure Storage Client Library 1.7, which has been deprecated. See Storage Client Library for the latest version.]

Converts a query of type DataServiceQuery to a CloudTableQuery object that handles continuation tokens and retries failed calls to the Table service.

Namespace: Microsoft.WindowsAzure.StorageClient
Assembly: Microsoft.WindowsAzure.StorageClient (in Microsoft.WindowsAzure.StorageClient.dll)

Usage

Visual Basic
Dim query As IQueryable(Of TElement)
Dim returnValue As CloudTableQuery(Of TElement)

returnValue = TableServiceExtensionMethods.AsTableServiceQuery(query)

Syntax

Visual Basic
<ExtensionAttribute> _
Public Shared Function AsTableServiceQuery(Of TElement) ( _
	query As IQueryable(Of TElement) _
) As CloudTableQuery(Of TElement)
C#
[ExtensionAttribute] 
public static CloudTableQuery<TElement> AsTableServiceQuery<TElement> (
	IQueryable<TElement> query
)
C++
[ExtensionAttribute] 
public:
generic<typename TElement>
static CloudTableQuery<TElement>^ AsTableServiceQuery (
	IQueryable<TElement>^ query
)
J#
JScript

GenericParameters

TElement

The type of the element.

Parameters

query

Type: System.Linq.IQueryable

A DataServiceQuery object.

Return Value

Type: Microsoft.WindowsAzure.StorageClient.CloudTableQuery

A CloudTableQuery object.

Example

The following code example queries entities using a simulated LIKE clause.

C# Copy Code
// Get contacts filtered by prefix.
public static List<ContactEntity> GetContactsByPrefix(string prefix)
{
    // Get data context.
    TableServiceContext context = tableClient.GetDataServiceContext();

    CloudTableQuery<ContactEntity> query;

    // Query entities to return names beginning with the specified letter.
    // Note that because wildcard queries are not supported, it's necessary to perform prefix  
    // matching by using string comparisons.
    if (!String.IsNullOrEmpty(prefix) && Char.IsLetter(prefix[0]))
    {
        char prefixChar = prefix[0];
        int nextCharValue = ((int)prefixChar) + 1;
        char nextChar = (char)nextCharValue;
        query = context.CreateQuery<ContactEntity>(tableName)
                .Where(e => (e.FirstName.CompareTo(prefixChar.ToString().ToUpper()) >= 0 
                    && e.FirstName.CompareTo(nextChar.ToString().ToUpper()) < 0))
                .AsTableServiceQuery<ContactEntity>();
    }
    else
    {
        query = context.CreateQuery<ContactEntity>(tableName).AsTableServiceQuery<ContactEntity>();
    }

    // Populate list of entities from query results.
    List<ContactEntity> list = new List<ContactEntity>();
    foreach (ContactEntity entity in query)
    {
        list.Add(entity);
    }

    return list;
}

// Class to represent the table schema
public class ContactEntity : TableServiceEntity
{
    public ContactEntity()
    {
    }

    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Email { get; set; }
    public string HomePhone { get; set; }
    public string CellPhone { get; set; }
    public string StreetAddress { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string ZipCode { get; set; }
}

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Platforms

Development Platforms

Windows Vista, Windows 7, Windows Server 2008, Windows 8.1, Windows Server 2012 R2, Windows 8 and Windows Server 2012

Change History

See Also